# -*- coding: utf-8 -*-
# @Time : 2021/9/17 22:24
# @Author : 伟哥
# @Email : xw@gmail.com
# @File : address_page.py
# @Project : mryx_test
'''收货地址页面的定位器以及操作'''
from time import sleep
from appium.webdriver.common.mobileby import MobileBy as By
from page.base_page import BasePage
from utils.util import send_keys
class Address(BasePage):
    '''收货地址'''
    add_locator = (By.XPATH, "//android.view.View[@content-desc=\"新增收货地址\"]")
    name_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().text("请填写收货人的姓名")')
    phone_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().text("请填写收货人手机号")')
    select_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().text("点击选择收货地址")')
    house_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().text("详细地址，例如：3号楼二单元105")')
    lable_locator = (By.XPATH, '//android.view.View[@content-desc=\"公司\"]')
    default_locator = (By.XPATH, "//android.widget.Switch")
    save_locator = (By.XPATH, '//android.view.View[@content-desc=\"保存收货信息\"]')
    assertion_locator = (By.XPATH, '//android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/'
              'android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/'
              'android.view.View[1]/android.view.View[1]/android.view.View[1]/android.view.View[1]/'
              'android.view.View[2]/android.view.View[1]/android.widget.ImageView[1]')
    delete_assertion_locator=(By.XPATH,'//android.widget.FrameLayout/android.view.View[1]/android.view.View[1]/android.view.View[1]/'
                                       'android.view.View[1]/android.widget.ImageView[1]')
    delete_locator = (By.XPATH, '//android.view.View[@content-desc=\"删除收货信息\"]')

    def add(self):
        '''点击新增收货地址'''
        self.driver.find_element(*self.add_locator).click()

    def name(self,name="行编辑"):
        '''输入收货人姓名'''
        send_keys(self.driver,self.name_locator,name)

    def phone(self,phone="13356789011"):
        '''输入手机号码'''
        send_keys(self.driver, self.phone_locator, phone)

    def select_address(self):
        '''输入收货地址'''
        self.driver.find_element(*self.select_locator).click()
        sleep(3)
        self.driver.tap([(314, 930)], 100)

    def house(self,house="规划进口美食"):
        '''输入门牌号'''
        send_keys(self.driver, self.house_locator, house)

    def lable(self):
        '''点击标签公司'''
        self.driver.find_element(*self.lable_locator).click()

    def default(self):
        '''取消或打开默认地址设置'''
        self.driver.find_element(*self.default_locator).click()

    def save(self):
        '''保存收货地址信息'''
        self.driver.find_element(*self.save_locator).click()

    def arrertion(self):
        '''第一条地址信息文本提取'''
        return self.driver.find_element(*self.assertion_locator).get_attribute("content-desc")

    def edit(self,ed=(680, 137)):
        '''点击编辑'''
        self.driver.tap([ed])

    def delefe(self):
        '''点击删除'''
        self.driver.find_element(*self.delete_locator).click()

    def enable_arrertion(self):
        '''判断断言的元素对象是否可用'''
        return self.driver.find_element(*self.delete_assertion_locator).is_enabled()


    def back(self,b=(34,64)):
        '''点击返回'''
        self.driver.tap([b])